﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Common.Tools;

namespace WindowsFormsApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.ScriptErrorsSuppressed = true;
            webBrowser1.Navigate("http://user.qzone.qq.com/827756467/main");
            webBrowser1.Navigating += (sender0, e0) =>
            {
                if (e0.Url.ToString().StartsWith("http://g.cnc.qzone.qq.com/cgi-bin/friendshow/cgi_get_visitor_simple"))
                    label1.Text = e0.Url.ToString();
            };
            webBrowser1.DocumentCompleted += (sender1, e1) =>
            {
                if (e1.Url.ToString().StartsWith("http://g.cnc.qzone.qq.com/cgi-bin/friendshow/cgi_get_visitor_simple"))
                    label1.Text = e1.Url.ToString();
            };
            while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Application.DoEvents();
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(label1.Text);
            webBrowser1.DocumentCompleted += (sender1, e1) =>
            {
                var htmldocument = (mshtml.HTMLDocument)webBrowser1.Document.DomDocument;
                string gethtml = htmldocument.documentElement.outerHTML;
                var iii = gethtml;
            };
            while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
             {
                 Application.DoEvents();
            }
           
            //CookieContainer myCookieContainer = new CookieContainer();

            //string cookieStr = webBrowser1.Document.Cookie;
            //string[] cookstr = cookieStr.Split(';');
            //foreach (string str in cookstr)
            //{
            //    string[] cookieNameValue = str.Split('=');
            //    Cookie ck = new Cookie(cookieNameValue[0].Trim().ToString(), cookieNameValue[1].Trim().Replace(",","%2C").ToString());
            //    ck.Domain = "g.cnc.qzone.qq.com";
            //    myCookieContainer.Add(ck);
            //}
            //try
            //{
            //    var ret = HttpRequestHelper.GetRequestWithCookie("", "http://g.cnc.qzone.qq.com/cgi-bin/friendshow/cgi_get_visitor_simple?uin=827756467&mask=3&clear=1&rd=0.9376698434352875&g_tk=1159856453", myCookieContainer);

            //}
            //catch (Exception ex)
            //{
                
            //}
        }

      
    }
}
